﻿@{
    ViewBag.Title = "DrugWareHouseValidity";
    Layout = "~/Views/Shared/_ViewMenu.cshtml";
}

@using ZX.HIS.Model;
@using ZX.HIS.Common;
@{
    List<ZX.HIS.Model.DrugTypeInfo> DrugTypeList = ViewData["liat"] as List<ZX.HIS.Model.DrugTypeInfo>;
}
<script src="~/Content/After/js/jquery.autoTextarea.js"></script>
<div id="urHere">DouPHP 管理中心<b>&gt;</b><strong>药品类型名</strong> </div>

<div class="mainBox" style="height:auto!important;height:550px;min-height:550px;">
    <h3>效期预警</h3>
    <div class="filter">
        <form action="/RegistType/RegistTypeShow" method="post">
            <lable class="drug-type">失效日期：</lable>
            <select name="drugType" id="drugDate">
                <option value="7">一周内</option>
                <option value="30" selected="selected">一个月内</option>
                <option value="60">两个月内</option>
                <option value="90">三个月内</option>
                <option value="180">半年内</option>
                <option value="365">一年内</option>
            </select>

            <lable class="drug-type">药品类型：</lable>
            <select id="DrugTypeId" name="DrugTypeId">
                <option value="">全部</option>
                @foreach (var item in DrugTypeList)
                {
                    <option value="@item.DrugTypeName">@item.DrugTypeName</option>
                }
            </select>
            <button type="button" class="btnGray" onclick="PageJump(1)">
                <span class="glyphicon glyphicon-search"></span>
            </button>
        </form>
    </div>
    <table width="100%" class="table table-bordered  tableBasic order-list table-list">
        <thead class="main-table-tbody J_drugList">
            <tr>
                <th class="table-title">药品名称</th>
                <th class="table-title">失效日期</th>
                <th class="table-title">药品分类</th>
                <th class="table-title">规格</th>
                <th class="table-title">生产厂家</th>
                <th class="table-title">库存</th>
            </tr>
        </thead>
        <tbody id="tbodyShow"></tbody>
    </table>
    <div class="divPage"></div>
</div>
<script src="~/Content/Command.js"></script>
<script>

    $(function () {
        //页面初次加载，调用AJAX，PageIndex 为1
        PageJump(1);
    })
    //分页数据加载方法
    function PageJump(PageIndex) {
        var PageSize = $("#PageSize").val();
        var drugDate = $("#drugDate").val();
        var DrugTypeId = $("#DrugTypeId").val();
        if (PageSize == "" || parseInt(PageSize) == 0 || PageSize == null) {
            PageSize = 10;
        }
        $.ajax({
            type: "POST",
            url: "/DrugWareHouse/pageDrugWareHouseshow",
            data: {
                PageIndex: PageIndex,
                drugDate: drugDate,
                DrugTypeId: DrugTypeId,
                PageSize: PageSize
            },
            success: function (data) {
                var TrDemo = new Array();
                var divDemo = new Array();
                if (data.PageList.length == 0) {
                    TrDemo.push("<tr><td colspan=\"9\" >无查询结果</td></tr>")
                } else {
                    for (var i = 0; i < data.PageList.length; i++) {
                        TrDemo.push("<tr>")
                        TrDemo.push("<td class=\"little-width\">");
                        TrDemo.push(data.PageList[i].DrugWareName);
                        TrDemo.push("</td><td>")
                        TrDemo.push(ChangeDateFormat(data.PageList[i].DrugWareTime));
                        TrDemo.push("</td><td>")
                        TrDemo.push(data.PageList[i].DrugTypeId);
                        TrDemo.push("</td><td>")
                        TrDemo.push(data.PageList[i].DrugWarePackSpece);
                        TrDemo.push("</td><td>")
                        TrDemo.push(data.PageList[i].ProductId);
                        TrDemo.push("</td><td>")
                        TrDemo.push(data.PageList[i].DrugWareNumber);
                        TrDemo.push("</td></tr>")
                    }
                }
                $("#tbodyShow").html(TrDemo.join(""));
                //调用分页索引条
                PageDemoSuccess(divDemo, data);
                $(".divPage").html(divDemo.join(""));
            }
        })
    }
    //分页索引条加载方法
    function PageDemoSuccess(divDemo, data) {
        divDemo.push("<nav>")
        divDemo.push("<ul class=\"pagination \">")
        divDemo.push("<li>")
        divDemo.push(" <span>每页");
        divDemo.push("<input type=\"number\" class=\"inpMain\"  min=\"1\" style=\"width:40px;height:12px\" id=\"PageSize\" value=\"")
        divDemo.push(data.PageSize);
        divDemo.push("\" placeholder=\"\" />");
        divDemo.push(" 条</span></li>")
        divDemo.push("<li><span>共" + data.PageCount + "页，第" + data.PageIndex + "页，共" + data.PageNum + "条</span></li>")
        divDemo.push("<li><span onclick=\"PageJump(1)\" aria-label=\"Previous\"><span aria-hidden=\"true\">首页</span></span></li>")
        if (data.PageIndex <= 1) {
            divDemo.push("<li class=\"disabled\"><span onclick=\"PageJump(1)\">上一页</span></li>")
        }
        else {
            divDemo.push("<li><span onclick=\"PageJump(" + (data.PageIndex - 1) + ")\">上一页</span></li>")
        }
        for (var i = 0; i < data.PageCount; i++) {
            if (data.PageCount > 8) {
                if (data.PageIndex == 1) {
                    if (i <= 3) {
                        if (i == 3) {
                            LiNoPush(divDemo);
                        } else {
                            LiJumpPush(data.PageIndex, i, divDemo)
                        }
                    } else {
                        break;
                    }
                }
                else if (data.PageIndex == data.PageCount) {

                    if (i >= (data.PageCount - 4)) {
                        if (i == data.PageCount - 4) {
                            LiNoPush(divDemo);
                        } else {
                            LiJumpPush(data.PageIndex, i, divDemo)
                        }
                    }
                    else {
                        continue;
                    }
                } else {
                    if ((data.PageIndex - 3) <= i && i <= (data.PageIndex + 1)) {
                        if (data.PageIndex - 3 == i) {
                            LiNoPush(divDemo);
                        } else if (data.PageIndex + 1 == i) {
                            LiNoPush(divDemo);
                        } else {
                            LiJumpPush(data.PageIndex, i, divDemo)
                        }
                    } else {
                        continue;
                    }
                }
            } else {
                LiJumpPush(data.PageIndex, i, divDemo)
            }
        }
        if (data.PageIndex == data.PageCount) {
            divDemo.push("<li class=\"disabled\"><span onclick=\"PageJump(" + data.PageCount + ")\">下一页</span></li>")
        }
        else {
            divDemo.push("<li><span onclick=\"PageJump(" + (data.PageIndex + 1) + ")\">下一页</span></li>")
        }
        divDemo.push(" <li><span onclick=\"PageJump(" + data.PageCount + ")\" aria-label=\"Next\"><span aria-hidden=\"true\">尾页</span></span></li>")
        divDemo.push("</ul>")
        divDemo.push("</nav>")
    }
    //分页链接跳转方法
    function LiJumpPush(PageIndex, Num, Demo) {
        Demo.push("<li ")
        if (PageIndex == (Num + 1)) {
            Demo.push(" class=\"active\"")
        }
        Demo.push("><span onclick=\"PageJump(" + (Num + 1) + ")\">" + (Num + 1) + "</span></li>")
    }
    //省略号加载方法
    function LiNoPush(Demo) {
        Demo.push("<li><span>...</span></li>")
    }
    function RadioSelect(e) {
        var id = $(e).val();
        location.href = "/DrugTypeInfo/UpateDrugTypeInfo/" + id;
    }
    //$(function () {
    //    $("#CK").click(function () {
    //        alert(1)
    //
    //    })
    //})

</script>